<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>试题维护</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <link href="/css/tikuCss/s-preserve.css" rel="stylesheet">
    <script src="/js/tikuJs/set.js"></script>
</head>
<body>
<style>
    th, td {
        border-top: none;
        border-right: 1px solid #dedede;
        width: 1%;
    }

    thead {
        background-color: #dedede;
    }

    td {
        border-top: 1px solid #dedede;
    }

    #show {
        border-top: none;
        border-left: none;
        border-right: none;
    }

    a {
        color: black;
        text-decoration: none;
        padding-right: 20px;
    }
</style>
<script>
    function find() {
        $.ajax({
            url: '/exam/findAll',
            data: {
                question_id: $("#question_id").val(),
                question_subject: $("#question_subject").val(),
                question_type: $("#question_type").val(),
                question_option: $("#question_option").val(),
                question_answer: $("#question_answer").val(),
                question_level: $("#question_level").val(),
                question_direction: $("#question_direction").val()
            },
            type: 'get',
            dataType: 'json',
            success: function (data) {
                console.log(data);
                show(data);
            }
        })
    }//查询

    function show(data) {
        let html = '';
        html += '<table><thead>' +
            '<th><input type="checkbox" id="checkall" style="float:left" onclick="setAllNo()"></th>' +
            '<th>试题ID</th>' +
            '<th>试题题目</th>' +
            '<th>试题类型</th>' +
            '<th>试题科目</th>' +
            '<th>试题答案</th>' +
            '<th>难易程度</th>' +
            '<th>试题方向</th>' +
            '<th>试题操作</th>' +
            ' </thead>';
        let da = data[0].data;
        for (let i = 0; i < da.length; i++) {
            html += '<tr>' +
                '<td><input type="checkbox" name="checkbox" class="checkitem"></td>' +
                '<td style="text-align:center">' + da[i].question_id + '</td>' +
                '<td style="text-align:center">' + da[i].question_subject + '</td>' +
                '<td style="text-align:center">' + da[i].question_type + '</td>' +
                '<td style="text-align:center">' + da[i].question_option + '</td>' +
                '<td style="text-align:center">' + da[i].question_answer + '</td>' +
                '<td style="text-align:center">' + da[i].question_level + '</td>' +
                '<td style="text-align:center">' + da[i].question_direction + '</td>' +
                '<td style="text-align:center">' +
                '<a href="javascript:xgexam(' + da[i].question_id + ')" class="aleft">修改</a>' +
                '<a href="javascript:delexam(' + da[i].question_id + ')" class="aright">删除</a>' +
                '</td>' +
                '</tr>';
        }
        html += '</table>';
        $("#show").html(html);
    }//将查询的结果显示到show里面

    function ad() {
        window.location.href = "/html/tikuHtml/sadd.html";
    }//添加

    function delexam(question_id) {
        alert("id为" + question_id + "数据：删除成功");
        $.ajax({
            url: '/exam/delete',
            data: {question_id: question_id},
            type: 'post',
            dataType: 'json',
            success: function (data) {
                console.log(data);
            }
        });
        window.location.href = "/html/tikuHtml/spreserve.html";
    }//删除

    function xgexam(question_id) {
        localStorage.setItem("question_id", question_id);
        window.location.href = "/html/tikuHtml/supdate.html";
    }//修改

    function finds() {
        var sousuo = $("#sousuo").val();
        if (sousuo == "") {
            alert("试题类型不能为空！");
            return false;
        } else {
            $.ajax({
                url: '/exam/ss',
                data: {
                    question_id: $("#question_id").val(),
                    question_subject: $("#question_subject").val(),
                    question_type: $("#question_type").val(),
                    question_option: $("#question_option").val(),
                    question_answer: $("#question_answer").val(),
                    question_level: $("#question_level").val(),
                    question_direction: $("#question_direction").val()
                },
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    show(data);
                }
            })
        }
    }
</script>
<form action="/exam/findAll">
    <table class="s-table">
        <tr>
            <td colspan="8" style="border-left: 0;border-right: 0;text-align: center;background-color:#dedede">
                <div style="font-weight: bolder">试题维护</div>
            </td>
        </tr>
        <tr>
            <td colspan="8">
                <input type="text" id="sousuo" name="sousuo" placeholder="搜索试题类型">
                <input type="button" value="搜索" onclick="finds()" style="margin-left: 10px" >
                <input type="button" value="全选" onclick="setAll()">
                <input type="button" value="反选" onclick="setOthers()">
                <input type="button" value="增加试题" onclick="ad()" >
                <input type="button" value="批量删除" onclick="delid()" id="delall">
                <input type="button" value="查询所有" onclick="find()">
            </td>
        </tr>
    </table>
    <div id="show"></div>
</form>
</body>
</html>